package cn.cdeden.knowledge.controller.online;


import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.StringUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.FilesRecentlyViewed;
import cn.cdeden.knowledge.domain.dto.FilesRecentlyDto;
import cn.cdeden.knowledge.domain.dto.FilesRecentlyViewedQueryParam;
import cn.cdeden.knowledge.service.FilesRecentlyViewedService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 查看文件管理
 */
@RestController
@RequiredArgsConstructor
//@Api(tags = "查看文件管理")
@RequestMapping("/api/filesRecentlyViewed")
public class FilesRecentlyViewedController {

    private final FilesRecentlyViewedService filesRecentlyViewedService;

    /**
     * 文件:最近查看文件
     * @param query
     * @param pageable
     * @return
     */
    @GetMapping("/query")
//    @Log("文件:最近查看文件")
//    @ApiOperation("查询查看文件")
//    @PreAuthorize("@el.check('filesRecentlyViewed:list')")
    public R<TableDataInfo<FilesRecentlyDto>> query(FilesRecentlyViewedQueryParam query, Pageable pageable){
//        PageInfo<FilesRecentlyDto> info = filesRecentlyViewedService.queryAll(query,pageable);
        TableDataInfo<FilesRecentlyDto> filesRecentlyDtoTableDataInfo = filesRecentlyViewedService.queryAll(query, pageable);

        return R.ok(filesRecentlyDtoTableDataInfo);
//        return BaseRespResult.successResultPage(info.getContent(), info.getTotalElements(), info.getSize());
    }

    @GetMapping("/check")
//    @Log("查看文件历史")
//    @ApiOperation("查看文件历史")
    public R<TableDataInfo<FilesRecentlyDto>> check(FilesRecentlyViewedQueryParam query, Pageable pageable){
        String libraryType = query.getLibraryType();
        TableDataInfo<FilesRecentlyDto> pageInfo = new TableDataInfo<>();
        if (StringUtils.isNullOrBlank(libraryType))throw new RuntimeException("参数传递错误");
        if (libraryType.equals("enterprise")){
            pageInfo = filesRecentlyViewedService.queryEnterpriseFile(query, pageable);
        } else if (libraryType.equals("team")) {
            pageInfo = filesRecentlyViewedService.queryTeamFile(query, pageable);
        }
        return R.ok(pageInfo);
    }
}
